<html>
<body onload = test();>
</body>
<script>
var singleton = function(fn){ 
    var result;
    return function(){
        return result || ( result = fn.apply(this,arguments));
    }
}
var createMask = singleton(function(){
return document.body.appendChild(document.createElement('div'));
});

function test() {
var a1 = createMask();
var a2 = createMask();
}
</script>
</html>